package com.zlq.dao;

import com.zlq.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao {

    //注入 JdbcTemplate
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public User queryUser(String username){

        String sql = "select * from user where username=?";
        //调用方法
        User user = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username);

        System.out.println("----------userDao------------");
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
//        Book book = jdbcTemplate.queryForObject(sql, new
//                BeanPropertyRowMapper<Book>(Book.class), id);
//        User user = new User();
//        user.setUsername("root");
//        user.setPassword("123456");



        return user;
    }

}
